#include "engine.h"
#include "EngineImpl.h"
#include <cassert>
#include <cstdlib>
namespace engine
{
	Engine* Engine::Create()
	{
		EngineImpl* self = new EngineImpl();
		self->AddRef();
		Engine* engine = reinterpret_cast<Engine*>(self);
		return engine;
	}

	bool Engine::Delete(engine::Engine *&engine)
	{
		if(engine != NULL)
		{
			EngineImpl* s = reinterpret_cast<EngineImpl*>(engine);
			s->Release();
			engine = NULL;
			return true;
		}
		else
			return false;
	}


	void EngineImpl::AddRef()
	{
		++ref;
		assert(ref > 0);
	}

	void EngineImpl::Release()
	{
		--ref;
		assert(ref >=0 );
		if(ref == 0)
		{
			delete this;
		}
	}


}